/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.example.chain;

import net.javlov.AbstractPrimitiveAction;
import net.javlov.Action;
import net.javlov.Agent;
import net.javlov.LearningRate;
import net.javlov.Option;
import net.javlov.Policy;
import net.javlov.State;

public class Move<T> extends AbstractPrimitiveAction<T> {


	private static final long serialVersionUID = -6177181838446326775L;

	public static final int LEFT = 0,
							RIGHT = 1;
	
	protected Chain world;
	protected int dir;
	
	public Move(Chain c, int direction) {
		if ( dir > RIGHT )
			throw new IllegalArgumentException();
		
		world = c;
		dir = direction;
	}
	
	@Override
	public void execute(Agent a) {
		if ( dir == LEFT )
			world.currentNode = world.currentNode.prev();
		else if ( dir == RIGHT )
			world.currentNode = world.currentNode.next();
	}
	
	@Override
	public Action firstStep(State<? extends T> s) {
		return this;
	}
	
	@Override
	public Action doStep(State<? extends T> s, double reward) {
		return this;
	}
	
	@Override
	public String toString() {
		return (dir == LEFT ? "L" : "R");
	}

}
